package io.renren;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.utils.MailSendComponent;
import io.renren.common.utils.RedisUtils;
import io.renren.modules.app.entity.CustomerEntity;
import io.renren.modules.app.service.CustomerService;
import io.renren.modules.sys.entity.SysUserEntity;
import lombok.Data;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.joda.time.DateTime;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.awt.dnd.DropTarget;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@RunWith(SpringRunner.class)
@SpringBootTest
public class Demo {
	@Autowired
	private RedisUtils redisUtils;

	@Autowired
	MailSendComponent mailSendComponent;

	@Resource
	private CustomerService customerService;


	@Test
	public void contextLoads() {
		SysUserEntity user = new SysUserEntity();
		user.setEmail("qqq@qq.com");
		redisUtils.set("user", user,100);

		System.out.println(ToStringBuilder.reflectionToString(redisUtils.get("user", SysUserEntity.class)));
	}
	@Test
	public void sendMail(){
		mailSendComponent.sandSimpleMail("1048405526@qq.com","260139486@qq.com",
				"1048405526@qq.com","测试邮件主题","测试邮件内容");

	}

	@Test
	public void queryTest(){
		Set set = new HashSet();
		System.out.println(set.contains(1));
	}

	@Test
	public void setTest(){
		String name = customerService.getObj(new QueryWrapper<CustomerEntity>().eq("user_id",100).select("username"),o -> (String) o);
		System.out.println(name);
	}

	@Test
	public void index(){
		Calendar calendar2 = Calendar.getInstance();
//		SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		calendar2.add(Calendar.DATE, -3);
		Date startTime = new Date();
		if(startTime == null){
			System.out.println(1111);
		}
		Date endTime = calendar2.getTime();
		System.out.println(endTime);
//		String three_days_after = sdf2.format(calendar2.getTime());
//		System.out.println(startTime.before(endTime));

//		List<Integer> list = Arrays.asList(1, 3, 2, 8, 11, 4);
//		List<Integer> list1 = list.stream().map(x-> x+3).collect(Collectors.toList());
//		System.out.println(list);
//		System.out.println(list1);
//		// 求和方式1
//		Optional<Integer> sum = list.stream().reduce((x, y) -> x + y);
//		// 求和方式2
//		Optional<Integer> sum2 = list.stream().reduce(Integer::sum);
//		// 求和方式3
//		Integer sum3 = list.stream().reduce(0, Integer::sum);
//
//		// 求乘积
//		Optional<Integer> product = list.stream().reduce((x, y) -> x * y);
//
//		// 求最大值方式1
//		Optional<Integer> max = list.stream().reduce((x, y) -> x > y ? x : y);
//		// 求最大值写法2
//		Integer max2 = list.stream().reduce(1, Integer::max);
//
//		System.out.println("list求和：" + sum.get() + "," + sum2.get() + "," + sum3);
//		System.out.println("list求积：" + product.get());
//		System.out.println("list求和：" + max.get() + "," + max2);
	}

	@Data
	class Person {
		private String name;  // 姓名
		private int salary; // 薪资
		private int age; // 年龄
		private String sex; //性别
		private String area;  // 地区

		// 构造方法
		public Person(String name, int salary, int age,String sex,String area) {
			this.name = name;
			this.salary = salary;
			this.age = age;
			this.sex = sex;
			this.area = area;
		}
		// 省略了get和set，请自行添加
	}

}
